<?php
/**
 * 跳转，如果url为空，则返回前一页/首页
 * 顺序: 参数$url > $_GET['burl'] > $_SERVER['HTTP_REFERER'] > index
 *
 * @param string $url
 * @access public
 * @return void
 */
function redirect( $url = null ) {

	//return redirect_sid( $url ); // @08/25/2010

	$to_url = null;
	if( null != $url ) {
		$to_url = $url;
	}
	elseif( isset( $_GET['burl'] ) ) {
		$to_url = $_GET['burl'];

	}
	elseif( isset( $_SERVER['HTTP_REFERER'] ) ) {
		$to_url = $_SERVER['HTTP_REFERER'];
	}
	else {
		$to_url = '/';
	}

	header( 'Location:' . $to_url );
	exit;
}
function redirect_sid( $url = null ) {
	global $msess;

	$to_url = null;
	if( null != $url ) {
		$to_url = $url;
	}
	elseif( isset( $_GET['burl'] ) ) {
		$to_url = $_GET['burl'];

	}
	elseif( isset( $_SERVER['HTTP_REFERER'] ) ) {
		$to_url = $_SERVER['HTTP_REFERER'];
	}
	else {
		$to_url = '/';
	}

	if( false === strpos( $to_url, 'sid' ) ) {
		$add_char = false == strpos( $to_url, '?' ) ? '?' : '&';
		$to_url = sprintf( '%s%ssid=%s', $to_url, $add_char, $msess->sid );
	}

	header( 'Location:' . $to_url );
	exit;
}

?>
